// ipc.ts
let ipcRenderer;

if (typeof window !== 'undefined' && window.require) {
  try {
    const electron = window.require('electron');
    ipcRenderer = electron.ipcRenderer;
  } catch (error) {
    console.warn('Electron IPC not available');
  }
}

export function sendMessage(channel: string, ...args: any[]) {
  if (ipcRenderer) {
    ipcRenderer.send(channel, ...args);
  } else {
    console.warn(`IPC message not sent: ${channel}`);
  }
}

export function onMessage(channel: string, listener: (...args: any[]) => void) {
  if (ipcRenderer ) {
    ipcRenderer.on(channel, listener);
  } else {
    console.warn(`IPC listener not added: ${channel}`);
  }
}